/*
 * Copyright 2010-2012 Susanta Tewari. <freecode4susant@users.sourceforge.net>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/*
* AnnealOModel.java
*
* Created on December 29, 2007, 10:39 AM
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
 */
package gui.genomemap.outputModel;

import genomemap.data.OrderElement;

import gui.genomemap.outputModel.options.AnnealOOptionsModel;

import java.util.Collection;
import java.util.LinkedHashSet;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;

/**
 *
 * @author stewari1
 */
@Entity
public class AnnealOModel extends OutputModel implements java.io.Serializable {

    /** Field description */
    public static final int FIG_GMAP = 0;

    /** Field description */
    public static final int FIG_PMAP = 1;

    /** Field description */
    public static final int FIG_FULLMAP = 2;

    /** Field description */
    public static final int FIG_IPMAP = 3;

    /** Field description */
    public static final int FIG_IGMAP = 4;

    /** Field description */
    public static final int FIG_IFULLMAP = 5;

    /** Field description */
    private double convValue = 0.0;

    /** Field description */
    private int contigCount = 0;

    /** Field description */
    @OneToMany(cascade = CascadeType.ALL)
    private Collection<OrderElement> orderSet = new LinkedHashSet<>();

    /** Field description */
    @OneToOne(cascade = CascadeType.ALL)
    private AnnealOOptionsModel optionsModel = new AnnealOOptionsModel();

    /** Creates a new instance of AnnealOModel */
    public AnnealOModel() {}

    @Override
    public int hashCode() {
        return super.hashCode() + new Double(getConvValue()).hashCode();
    }

    @Override
    public boolean equals(Object obj) {

        if (obj instanceof AnnealOModel) {

            AnnealOModel annealOModel = (AnnealOModel) obj;

            return super.equals(annealOModel) && (getConvValue() == annealOModel.getConvValue());
        }

        return false;
    }

    public int[] getOrder() {

        OrderElement[] array = getOrderSet().toArray(new OrderElement[0]);
        int[] order          = new int[array.length];

        for (int index = 0; index < order.length; index++) {

            order[index] = array[index].getVal();
        }

        return order;
    }

    public void setOrder(int[] order) {

        for (int val : order) {

            getOrderSet().add(new OrderElement(val));
        }
    }

    public AnnealOOptionsModel getOptionsModel() {
        return optionsModel;
    }

    public void setOptionsModel(AnnealOOptionsModel optionsModel) {
        this.optionsModel = optionsModel;
    }

    public double getConvValue() {
        return convValue;
    }

    public void setConvValue(double lHood) {
        this.convValue = lHood;
    }

    public Collection<OrderElement> getOrderSet() {
        return orderSet;
    }

    public void setOrderSet(Collection<OrderElement> orderSet) {
        this.orderSet = orderSet;
    }

    public int getContigCount() {
        return contigCount;
    }

    public void setContigCount(int contigCount) {
        this.contigCount = contigCount;
    }
}
